<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>保险订单列表</title>
    <link rel="stylesheet" href="/adminthemes/layui/css/layui.css" media="all">
    <!-- jQuery -->
    <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<br>
<br>
<div class="demoTable" style="margin-left: 5%">
    账户名称：
    <div class="layui-inline">
        <input class="layui-input" name="id" id="demoReload" autocomplete="off">
    </div>
    <button class="layui-btn" data-type="reload">搜索</button>
</div>
<table id="demo"  lay-data="{id:'demo'}" lay-filter="demo" style="margin-left: 20%;margin-right: 20%"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">审核通过</a>
</script>
</body>
<script src="/adminthemes/layui/layui.js"></script>
<script>
    layui.use('table', function(){
        var table = layui.table;
        //第一个实例
        table.render({
            elem: '#demo'
            ,height: 315
            ,limit:10
            ,id:"rbt"
            ,request: {
                pageName: 'page' //页码的参数名称，默认：page
                ,limitName: 'limit'//每页数据量的参数名，默认：limit
            }
            ,url: '/web/InPolicyOrd/getAllIProtOrd1.do' //数据接口
            ,page: true //开启分页
            // ,cellMinWidth:100
            ,cols: [[
                {field:'warranty_number', width:200, title: '保单编号', sort: true}
                ,{field:'goods_name', width:150, title: '险种名称'}
                ,{field:'applicant_name', width:100, title: '投保人', sort: true}
                ,{field:'insurant_name', width:100, title: '被投保人'}
                ,{field:'policy_mobile', width:150,title: '投保人联系电话'}
                ,{field:'insured_quantity', width:100, title: '投保数量', sort: true}
                ,{field:'right', title: '操作', width:177, align:'center',toolbar:"#barDemo"}
            ]]
        });

        var $ = layui.$, active = {
            reload: function(){
                var demoReload = $('#demoReload').val();
                //执行重载
                table.reload('rbt', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        seacher: demoReload
                    }
                });
            }
        };
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.warranty_id + ' 的查看操作');
            }else if(obj.event === 'edit'){
                layer.prompt({
                    formType: 2
                    ,value: data.uv
                }, function(value, index){
                    //这里一般是发送修改的Ajax请求
                    EidtUv(data,value,index,obj);
                });
            }
        });
        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
    function  EidtUv(data,value,index,obj) {
        $.ajax({
            url: "/web/InPolicyOrd/checkInPolicyOrd.do",
            type: "POST",
            data: {"inPolicy_id": data.warranty_id,"checkType":1},
            dataType: "json",
            success: function (data) {
                if (data.result == 1) {
                    //关闭弹框
                    layer.close(index);
                    //同步更新表格和缓存对应的值
                    obj.update({
                        uv: value
                    });
                    layer.msg("修改成功", {icon: 6});
                } else {
                    layer.msg("修改失败", {icon: 5});
                }
            }
        });
    }
</script>
</body>
</html>